import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class MyStack {
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        Stack<Integer> stack = new Stack();
        int j = 0;
        for(int i = 0;i < pushV.length;i++){
            stack.push(pushV[i]);
            while(!stack.empty() && stack.peek() == popV[j] && j < popV.length){
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }

    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack();
        for(String str : tokens){
            if(!isOperations(str)){
                stack.push(Integer.parseInt(str));
            }else{
                int val2 = stack.pop();
                int val1 = stack.pop();
                switch(str){
                    case "+":
                        stack.push(val1 + val2);
                        break;
                    case "-":
                        stack.push(val1 - val2);
                        break;
                    case "*":
                        stack.push(val1 * val2);
                        break;
                    case "/":
                        stack.push(val1 / val2);
                        break;
                }
            }
        }
        return stack.pop();
    }
    private boolean isOperations(String str){
        if(str.equals("+") || str.equals("-") || str.equals("*") || str.equals("/")){
            return true;
        }
        return false;
    }
    Queue<Integer> queue1;
    Queue<Integer> queue2;
    public MyStack() {
        queue1 = new LinkedList<>();
        queue2 = new LinkedList<>();
    }

    public void push(int x) {
        queue2.offer(x);
        while(!queue1.isEmpty()){
            queue2.offer(queue1.poll());
        }
        Queue<Integer> temp=queue1;
        queue1=queue2;
        queue2=temp;
    }

    public int pop() {
        return queue1.poll();
    }

    public int top() {
        return queue1.peek();
    }

    public boolean empty() {
        return queue1.isEmpty();
    }
}
